package myschool.test3;

import myschool.dao.ExamDao;
import myschool.dao.GradeDao;
import myschool.entity.ExamResult;
import myschool.entity.Grade;
import myschool.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.cache.impl.PerpetualCache;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
public class MybatisCache {
    public static void main(String[] args) {
        //level1();
        level2(1);
//        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
         level2(2);
        //delExam();
    }
    public static void delExam(){
        SqlSession s = MyBatisUtil.get();
        ExamDao mapper = s.getMapper(ExamDao.class);
        int del = mapper.del(19);
        System.out.println("删除的结果是："+del);
        MyBatisUtil.close(s);
    }

    public static void level2(int pageNo) {
        SqlSession s = MyBatisUtil.get();
        ExamDao mapper = s.getMapper(ExamDao.class);
        List<ExamResult> list = mapper.pag2(pageNo, 10);
        for (ExamResult r : list) {
            System.out.println(r+".."+r.getSubject());
        }
        MyBatisUtil.close(s);
    }

    public static void level1() {
        SqlSession s = MyBatisUtil.get();
        GradeDao mapper = s.getMapper(GradeDao.class);
        Grade grade = mapper.get(1L);

        System.out.println("年级信息:" + grade);
        System.out.println("此年级的学生信息如下：");
        grade.getStus().forEach(System.out::println);
        Grade grade2 = mapper.get(1L);
        System.out.println("第二次年级信息：" + grade2);
        System.out.println(grade == grade2);
        MyBatisUtil.close(s);
    }
}
